// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

var Take6Model = require("Take6Model");

cc.Class({
    extends: cc.Component,

    properties: {
        bCanBeTouched : true,
        bSelected : false,
        nScore : 0,
        nIndex : -1,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad : function () 
    {
        this.node.on('touchend', function ( event )
        {
            if (this.bCanBeTouched == true)
            {
                this.bSelected = true;
                // 暂时放在这儿 实际应该放在后台回调 这里只负责向后台发送数据
                // cc.find("Canvas").emit('event_player_select_a_group', {});
                Take6Model.playerTakeGroupToServer(this.nIndex);
            }

        }, this);
    },

    setIndex : function(nIndex)
    {
        this.nIndex = nIndex;
    },

    setScore : function(nScore, bCanBeTouched)
    {
        var node = this.node;
        var arrowLabel = node.getChildByName("arrowLabel").getComponent(cc.Label);

        arrowLabel.string = nScore.toString();
        this.nScore = nScore;

        this.bSelected = false;
        cc.log("set Arrow Score");

        node.stopAllActions();
        this.startAnimation();

        this.bCanBeTouched = bCanBeTouched;
    },

    startAnimation : function()
    {
        var actionShorter = cc.scaleTo(0.7, 1.1, 0.95);
        var actionTaller = cc.scaleTo(0.7, 0.95, 1.05);
        var actionUnion = cc.sequence(actionShorter, actionTaller);
        var actionRepeat = cc.repeatForever(actionUnion);

        this.node.runAction(actionRepeat);
    },

    start () {

    },

    // update (dt) {},
});
